﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;

namespace FAS.Common.Repository.Nhb
{
   public class WpfSessionStorage:ISessionStorage
    {
       [ThreadStatic]
       private static ISession _threadSession = null;
       public WpfSessionStorage() { }

       public ISession Get()
       {
           if (_threadSession != null)
           {
               if (_threadSession.IsConnected)
                   _threadSession.Reconnect();
           }
           return _threadSession;
       }
       public void Set(ISession session)
       {
           if (_threadSession != null)
           {
               if (_threadSession.IsConnected)
               {
                   session.Disconnect();
               }
           }
           _threadSession = session;
       }
    }
}
